using System.Data.SqlClient;
using NUnit.Framework;

namespace DatabaseUnitTesting.Tests
{
    [TestFixture]
    public class DatabaseComparerTests
    {
        private SqlConnection connection;
        private DatabaseComparer comparer;

        [TestFixtureSetUp]
        public void TestFixtureSetUp()
        {
            string database = "astyler";
            string server = "(local)";
            string connectionString = "Application Name=UnitTests;Trusted_Connection=true;Server=" + server +
                                      ";Database=" + database;
            connection = new SqlConnection(connectionString);
            connection.Open();

            comparer = new DatabaseComparer(connection, "comparer1", "comparer2");
        }

        [TestFixtureTearDown]
        public void TestFixtureTearDown()
        {
            connection.Close();
        }

        [SetUp]
        public void SetUp()
        {
            comparer.BeginTestTransaction();
        }

        [TearDown]
        public void TearDown()
        {
            comparer.EndTestTransaction();
        }



        [Test]
        public void MappingsTest()
        {
            comparer.AddObjectComparison("dbo", "unitTestView", "dbo", "unitTestView");
            comparer.AddObjectComparison("dbo", "unitTestView", "dbo", "unitTestTable");
            comparer.AddObjectComparison("dbo", "unitTestTable", "dbo", "unitTestView");
            Assert.IsTrue(comparer.AreEqual());
        }

        [Test]
        public void MappingsTest2()
        {
            comparer.AddObjectComparison("dbo", "unitTestShortView", "dbo", "unitTestView");
            Assert.IsFalse(comparer.AreEqual());
        }

        [Test]
        public void MappingsTest3()
        {
            comparer.AddObjectComparison("dbo", "unitTestShortView", "dbo", "unitTestTable");
            Assert.IsFalse(comparer.AreEqual());
        }
    }
}
